package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

import com.yuexunit.finance.member.entity.lexicon.AuditStateEnum;
import com.yuexunit.finance.project.FinanceCancelApplicationService;
import com.yuexunit.finance.project.entity.FinanceCancelApplicationEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.page.PageCriteria;
import com.yuexunit.page.PageList;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;
import com.yuexunit.util.DateUtil;

/**
*@version 创建时间：2017年1月13日 下午2:50:10
*@author wenwenlong
*类说明
*/

@Implements(FinanceCancelApplicationService.class)
public class FinanceCancelApplicationServiceImpl implements FinanceCancelApplicationService {

	@Override
	@Transactional
	public Long createFinanceCancelApplication(FinanceCancelApplicationEntity entity) {
		entity.setCreateDateTime(DateUtil.now());
		entity.setUpdateDateTime(DateUtil.now());
		entity.setAuditState1(AuditStateEnum.UNAUDIT);
		PersistUtil.insert(entity);
		return entity.getCancelId();
	}

	@Override
	@Transactional
	public void updateFinanceCancelApplication(FinanceCancelApplicationEntity entity) {
		entity.setUpdateDateTime(DateUtil.now());
		PersistUtil.update(entity);
	}

	@Override
	public FinanceCancelApplicationEntity inquireFinanceCancelApplication(Long cancelId) {
		return PersistUtil.get(FinanceCancelApplicationEntity.class, cancelId);
	}

	@Override
	public List<FinanceCancelApplicationEntity> inqurieFinanceCancelApplicationList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceCancelApplicationEntity.class);
		return PersistUtil.get(criteria);
	}

	@Override
	public PageList<FinanceCancelApplicationEntity> inquireFinanceCancelApplicationPageList(PageCriteria page) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceCancelApplicationEntity.class);
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria, page);
	}
}
